#ifndef __i2c_soft_h__
#define __i2c_soft_h__

#include "gd32f4xx.h"
#include "gd32f4xx_gpio.h"
#include "systick.h"

#define I2C_RCU_PORN RCU_GPIOB
#define I2C_SCL_PORN GPIOB
#define I2C_SDA_PORN GPIOB

#define I2C_SCL_PIN GPIO_PIN_6
#define I2C_SDA_PIN GPIO_PIN_7

#define SCL(bit) gpio_bit_write(I2C_SCL_PORN, I2C_SCL_PIN, bit)
#define SDA(bit) gpio_bit_write(I2C_SDA_PORN, I2C_SDA_PIN, bit)

#define I2C_DELAY() delay_1us(10)

// #define I2C_SDA_OUT()                                                           \
//     gpio_mode_set(I2C_SDA_PORN, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, I2C_SDA_PIN); \
//     gpio_output_options_set(I2C_SDA_PORN, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, I2C_SDA_PIN);
// #define I2C_SDA_IN() gpio_mode_set(I2C_SDA_PORN, GPIO_MODE_INPUT, GPIO_PUPD_NONE, I2C_SDA_PIN);

void i2c_soft_config(void);

void i2c_sda_out(void);

void i2c_sda_in(void);

void i2c_soft_start(void);
uint8_t i2c_soft_write(uint8_t addr, uint8_t rega, uint8_t *data, uint32_t len);
uint8_t i2c_soft_read(uint8_t addr, uint8_t rega, uint8_t *data, uint32_t len);

void i2c_soft_test(void);

#endif
